import { createRouter, createWebHistory } from 'vue-router';

const modules = import.meta.glob('./*.js');
const filteredModules = Object.fromEntries(Object.entries(modules).filter(([path]) => !path.includes('index.js')));

const routerList = await Promise.all(Object.values(filteredModules).map((item) => item()));
const childrenRoutes = routerList.map((mod) => mod.default || mod).flat();

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('@/layout/Index.vue'),
      children: childrenRoutes,
    },
  ],
});

export default router;
